import * as YvanUI from '../index'

const React = YvanUI.React

interface INP {

}

interface Ref {

}

export default class Data1 extends YvanUI.Scope<INP, Ref> {

    main = this.$$({
        form1: {
            f1: '',
            f2: ''
        },
        form2: {
            f1: '',
            f2: ''
        }
    })

    vjson = this.$$({
        title: '标题',
        items: [
            {
                view: 'row',
                items: [
                    {
                        view: 'text',
                        bind: 'form1.f1',
                        visible: this
                            .$watch(() => [this.main.form1.f1, this.main.form1.f2],
                                ([f1, f2]) => new Promise<boolean>(resolve => {
                                    setTimeout(() => {
                                        resolve(true)
                                    }, 3000)
                                }),
                                {fireImmediately: true, delay: 10})
                        ,
                        disabled: this.$when(false,
                            () => this.main.form1.f1 !== '',
                            () => new Promise<boolean>(resolve => {
                                setTimeout(() => {
                                    resolve(true)
                                }, 3000)
                            }), {timeout: 10}),
                    },
                    {
                        view: 'button',
                        onClick: () => {
                            this.watch(() => this.main.form1.f1, () => {

                            })
                        }
                    }
                ]
            }
        ]
    })
}
